package com.tas.WebDriverTool;

import com.tas.WebDriverTool.WebDriver.WebDriver;
import com.webex.wbxtf.WBXTFTool;

public class WebDriverToolBusiness {
	
	/*
	 * Private variables definition
	 * 
	 */
	private WBXTFTool 		m_oTool = null;
	private boolean 		m_bInit = false;
	
	/*
	 * Business nodes
	 */
	private WebDriver	m_oWebDriverNode = null;
	
	public static final String  WEBDRIVER_TOOL_NAME = "WebDriverTool"; 
	
	private static WebDriverToolBusiness g_wdToolBiz = null;
	
	
	/*
	 * Set this constructor function as private to use singleton pattern.
	 * 
	 */
	private WebDriverToolBusiness(){}
	
	/*
	 * Get singleton WebDriverToolBusiness instance object
	 * @return WebDriverToolBusiness instance object
	 */
	public static WebDriverToolBusiness getSingleton()
	{
		if ( g_wdToolBiz == null )
			g_wdToolBiz = new WebDriverToolBusiness();
		
		return g_wdToolBiz;
	}
	
	public void initWBXTF()
	{
		if ( m_bInit == true )
			return;
		
		/*
		 * Init all sub nodes
		 */
		//Demoe node: TestNode
		m_oWebDriverNode = new WebDriver();
		
		/*
		 * Init tool root node
		 */
		m_oTool = new WBXTFTool(WBXTFTool.MODE_CORBA);
		
		m_oTool.init(WEBDRIVER_TOOL_NAME);
		//Add all sub nodes
		m_oTool.addRoot(m_oWebDriverNode, "WebDriver");
		
		
		m_bInit = true;
		m_oTool.runAsync();
	}
	
	public void unInitWBXTF()
	{
		if ( m_bInit == false )
			return;
		else
			m_bInit = false;
		
		m_oTool.halt();
		
		m_oTool.unInit();
		
		m_oTool = null;
		m_oWebDriverNode = null;
		
	}
}
